#include <bits/stdc++.h>

#define x first
#define y second
#define endl '\n'
#define int long long
#define NO {puts("NO"); return;}
#define YES {puts("YES"); return;}

using namespace std;

typedef long long ll;
typedef pair<int, int> PII;

const int MOD = 1e9 + 7;
const int N = 1e6 + 10, INF = 1e18;

int n, m;
int a[N], b[N];

int read()
{
	int x = 0, f = 1;
	char c = getchar();
	while (c < '0' || c > '9') { if (c == '-') f = -1; c = getchar(); }
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * f;
}

void slove()
{
	cin >> n;
	vector<int> v[3 + 1];
	map<int, int> cnt;
	for (int i = 1; i <= n; i++) {
		int t, id;
		cin >> t;
		while (t--) {
			cin >> id;
			cnt[id] ++;
			v[i].push_back(id);
		}
	}


	vector<int> ans;
	for (int i = 1; i <= n; i++) {
		for (int j : v[i]) cnt[j] --;
		for (int j : v[i]) {
			if (!cnt[j]) {
				ans.push_back(j);
				break;
			}
		}
	}
	if (ans.size() == n) {
		for (int i : ans) cout << i << " ";
		cout << endl;
	}
	else {
		cout << -1 << endl;
	}
}

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int t = 1;
	cin >> t;
	while (t--) slove();
	return 0;
}